package sliver.action;

import com.opensymphony.xwork2.ActionSupport;

public abstract class APIAction extends ActionSupport{
	private static final long serialVersionUID = 5548608788693017028L; 
	
	private String type;
	private String returnName;
	
	protected abstract String getResultJsonString();
	
	@Override
	public String execute() throws Exception {
		if(type.equals("js")){
			//"text/javascript"
			System.out.println("var" + this.returnName + " = " + getResultJsonString() + ";");
		}
		else if(type.equals("jsonp")){
			//"text/javascript"
			System.out.println(this.returnName + "(" + getResultJsonString() + ");");
		}
		else {
			//"application/json"
			System.out.println(getResultJsonString());
		}
		return null;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getReturnName() {
		return returnName;
	}

	public void setReturnName(String returnName) {
		this.returnName = returnName;
	}
	
	
}
